(use-modules
 ;; for unit testing forms
 (srfi srfi-64))

(use-modules
 ;; import the module to test
 (path-handling))


(test-begin "path-handling-test")

(test-group
 "absolute-path-test"

 (define path-to-current-dir
   (dirname (or (current-filename)
                (canonicalize-path "."))))

 (define non-existing-file-name
   "non-existing-file.txt")

 (display
  (simple-format
   #f "non existing file: ~a\n"
   (absolute-path non-existing-file-name)))

 (display
  (simple-format
   #f "path to current directory: ~a\n"
   path-to-current-dir))

 ;; absolute path existing
 (test-eqv path-to-current-dir (absolute-path path-to-current-dir))
 (test-assert (absolute-path? (absolute-path path-to-current-dir)))

 ;; absolute path not existing
 (test-eqv "/a/b/c" (absolute-path "/a/b/c"))
 (test-assert (absolute-path? (absolute-path "/a/b/c")))

 ;; non-absolute path existing
 (test-equal (string-append path-to-current-dir
                          file-name-separator-string
                          (basename (current-filename)))
   (absolute-path (current-filename) #:working-directory path-to-current-dir))
 (test-assert (absolute-path? (absolute-path (current-filename))))

 ;; non-absolute path not existing
 (test-assert (not (file-exists? non-existing-file-name)))
 (test-equal (string-append path-to-current-dir
                          file-name-separator-string
                          non-existing-file-name)
   (absolute-path non-existing-file-name #:working-directory path-to-current-dir))
 (test-assert (absolute-path? (absolute-path non-existing-file-name))))

(test-group
 "path-join-test"

 (test-equal "a/b/c" (path-join "a" "b" "c"))

 (test-equal "/a/b/c" (path-join "" "a" "b" "c"))

 (test-equal "/b/c" (path-join "" "a" "/b" "c"))

 (test-equal "/c" (path-join "" "a" "b" "/c")))

;; Finish the testsuite, and report results.
(test-end "path-handling-test")
